package com.yjkf.zh.admin.service.impl;

import com.yjkf.zh.admin.dao.SysCollectMapper;
import com.yjkf.zh.admin.dao.SysDeviceCollectMapper;
import com.yjkf.zh.admin.model.SysCollect;
import com.yjkf.zh.admin.model.SysDeviceCollect;
import com.yjkf.zh.admin.service.SysDeviceCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

import java.util.List;


@Service
public class SysDeviceCollectServiceImpl implements SysDeviceCollectService {

    @Autowired
    private SysDeviceCollectMapper sysDeviceCollectMapper;

    @Autowired
    private SysCollectMapper sysCollectMapper;

    @Override
    public int save(SysDeviceCollect sysDeviceCollect) {
        return sysDeviceCollectMapper.save(sysDeviceCollect);
    }

    @Override
    public int savaList(List<SysDeviceCollect> sysDeviceCollectList,Long userId) {
        SysCollect sysCollect = new SysCollect();
        Long pointCount =new Long(sysDeviceCollectList.size());
        Long userDeviceId = sysDeviceCollectList.get(0).getUserDeviceId();
        Long id  = sysDeviceCollectList.get(0).getCollectId();
        sysCollect.setPointCount(pointCount);
        sysCollect.setUserDeviceId(userDeviceId);
        sysCollect.setId(id);
        sysCollectMapper.update(sysCollect);
        for(SysDeviceCollect sysDeviceCollect:sysDeviceCollectList) {
            sysDeviceCollect.setUserId(userId);
            sysDeviceCollect.setCreateTime(new Date());
            save(sysDeviceCollect);
        }
        return 1;
    }

    @Override
    public List<SysDeviceCollect> findTableData(Long collectId,Long userId) {
        return sysDeviceCollectMapper.findTableData(collectId,userId);
    }



}
